// 实现组合函数
function hyCompose(...fns) {
  var len = fns.length
  for (let i = 0; i < len; i++) {
    if (typeof fns[i] !== 'function') {
      throw new TypeError("需要为函数类型")
    }
  }
  function compose(...args) {
    var index = 0
    var res = len ? fns[index].apply(this, args) : args
    while(++index < len) {
      res = fns[index].call(this, res)
    }
    return res
  }
  return compose
}

function double(n) {
  return n * 2
}

function square(n) {
  return n ** 2
}

let foo = hyCompose(double, square) // 实现了数字先乘 2 再平方的运算
console.log(foo(10)); // 400